package com.h2cloud.JUCTest.threadPool;

import java.util.concurrent.*;

/**
 * @Package: com.h2cloud.JUCTest.threadPool
 * @ClassName: FutureTaskTest
 * @Author: h2cloud
 * @CreateTime: 2024/1/12 10:37 下午
 * @Description:
 */
public class FutureTaskTest {
	public static void main(String[] args) {
		ExecutorService executorService = Executors.newFixedThreadPool(2);
		Future<String> stringFuture = executorService.submit(() -> {
			Thread.sleep(6000);
			return "2333";
		});

		executorService.execute(() -> {
			String s = null;
			try {
				s = stringFuture.get();
			} catch (InterruptedException | ExecutionException e) {
				e.printStackTrace();
			}
			System.out.println("s = " + s);
		});

		String s = null;
		try {
			s = stringFuture.get();
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		System.out.println("main s = " + s);
	}
}
